package com.caipos.actor.common.data.queue.discovery;

import com.caipos.actor.common.data.StringUtils;
import jakarta.annotation.PostConstruct;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.stream.Collectors;


@Component
@Slf4j
public class DefaultKbServiceInfoProvider implements KbServiceInfoProvider {

    @Getter
    @Value("${service.id:#{null}}")
    private String serviceId;

    @Getter
    @Value("${service.type:monolith}")
    private String serviceType;

    @Getter
    @Value("${service.rule_engine.assigned_tenant_profiles:}")
    private Set<UUID> assignedTenantProfiles;

    @Autowired
    private ApplicationContext applicationContext;


    @PostConstruct
    public void init() {
        if (StringUtils.isEmpty(serviceId)) {
            try {
                serviceId = InetAddress.getLocalHost().getHostName();
            } catch (UnknownHostException e) {
                serviceId = StringUtils.randomAlphabetic(10);
            }
        }
//        log.info("Current Service ID: {}", serviceId);
//        if (serviceType.equalsIgnoreCase("monolith")) {
//            serviceTypes = List.of(ServiceType.values());
//        } else {
//            serviceTypes = Collections.singletonList(ServiceType.of(serviceType));
//        }
//        if (!serviceTypes.contains(ServiceType.TB_RULE_ENGINE) || assignedTenantProfiles == null) {
//            assignedTenantProfiles = Collections.emptySet();
//        }
//
//        generateNewServiceInfoWithCurrentSystemInfo();
    }
//
//    @AfterContextReady
//    public void setTransports() {
//        serviceInfo = ServiceInfo.newBuilder(serviceInfo)
//                .addAllTransports(getTransportServices().stream()
//                        .map(TbTransportService::getName)
//                        .collect(Collectors.toSet()))
//                .build();
//    }
//
//    private Collection<TbTransportService> getTransportServices() {
//        return applicationContext.getBeansOfType(TbTransportService.class).values();
//    }

}
